﻿using System;
using System.ComponentModel;
using Loki.Utils;

namespace Luna.Model.CRM
{
    internal class EditableContact : Contact, IEditableContact
    {
        public EditableContact()
        {
        }

        public EditableContact(Contact contact)
            : base(contact)
        {
        }

        private static PropertyChangedEventArgs argsAccountChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Account);

        private static PropertyChangingEventArgs argsAccountChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Account);

        public new IAccount Account
        {
            get
            {
                return GetEntity(ApplicationModel.CRM.Accounts, Data.AccountID);
            }

            set
            {
                var buffer = value == null ? Guid.Empty : value.ID;
                if (buffer != Data.AccountID)
                {
                    NotifyChanging(argsTitleChanging);
                    Data.AccountID = buffer;
                    NotifyChangedAndDirty(argsTitleChanged);
                }
            }
        }

        #region Title

        private static PropertyChangedEventArgs argsTitleChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Title);

        private static PropertyChangingEventArgs argsTitleChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Title);

        public new string Title
        {
            get
            {
                return Data.Title;
            }

            set
            {
                if (value != Data.Title)
                {
                    NotifyChanging(argsTitleChanging);
                    Data.Title = value;
                    NotifyChangedAndDirty(argsTitleChanged);
                }
            }
        }

        #endregion Title

        #region Name

        private static PropertyChangedEventArgs argsNameChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Name);

        private static PropertyChangingEventArgs argsNameChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Name);

        public new string Name
        {
            get
            {
                return Data.Name;
            }

            set
            {
                if (value != Data.Name)
                {
                    NotifyChanging(argsNameChanging);
                    Data.Name = value;
                    NotifyChangedAndDirty(argsNameChanged);
                }
            }
        }

        #endregion Name

        #region GivenName

        private static PropertyChangedEventArgs argsGivenNameChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.GivenName);

        private static PropertyChangingEventArgs argsGivenNameChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.GivenName);

        public new string GivenName
        {
            get
            {
                return Data.GivenName;
            }

            set
            {
                if (value != Data.GivenName)
                {
                    NotifyChanging(argsGivenNameChanging);
                    Data.GivenName = value;
                    NotifyChangedAndDirty(argsGivenNameChanged);
                }
            }
        }

        #endregion GivenName

        #region Address

        private static PropertyChangedEventArgs argsAddressChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Address);

        private static PropertyChangingEventArgs argsAddressChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Address);

        public new string Address
        {
            get
            {
                return Data.Address;
            }

            set
            {
                if (value != Data.Address)
                {
                    NotifyChanging(argsAddressChanging);
                    Data.Address = value;
                    NotifyChangedAndDirty(argsAddressChanged);
                }
            }
        }

        #endregion Address

        #region City

        private static PropertyChangedEventArgs argsCityChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.City);

        private static PropertyChangingEventArgs argsCityChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.City);

        public new string City
        {
            get
            {
                return Data.City;
            }

            set
            {
                if (value != Data.City)
                {
                    NotifyChanging(argsCityChanging);
                    Data.City = value;
                    NotifyChangedAndDirty(argsCityChanged);
                }
            }
        }

        #endregion City

        #region Country

        private static PropertyChangedEventArgs argsCountryChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Country);

        private static PropertyChangingEventArgs argsCountryChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Country);

        public new string Country
        {
            get
            {
                return Data.Country;
            }

            set
            {
                if (value != Data.Country)
                {
                    NotifyChanging(argsCountryChanging);
                    Data.Country = value;
                    NotifyChangedAndDirty(argsCountryChanged);
                }
            }
        }

        #endregion Country

        #region Fax

        private static PropertyChangedEventArgs argsFaxChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Fax);

        private static PropertyChangingEventArgs argsFaxChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Fax);

        public new string Fax
        {
            get
            {
                return Data.Fax;
            }

            set
            {
                if (value != Data.Fax)
                {
                    NotifyChanging(argsFaxChanging);
                    Data.Fax = value;
                    NotifyChangedAndDirty(argsFaxChanged);
                }
            }
        }

        #endregion Fax

        #region Function

        private static PropertyChangedEventArgs argsFunctionChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Function);

        private static PropertyChangingEventArgs argsFunctionChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Function);

        public new string Function
        {
            get
            {
                return Data.Function;
            }

            set
            {
                if (value != Data.Function)
                {
                    NotifyChanging(argsFunctionChanging);
                    Data.Function = value;
                    NotifyChangedAndDirty(argsFunctionChanged);
                }
            }
        }

        #endregion Function

        #region Mail

        private static PropertyChangedEventArgs argsMailChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Mail);

        private static PropertyChangingEventArgs argsMailChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Mail);

        public new string Mail
        {
            get
            {
                return Data.Mail;
            }

            set
            {
                if (value != Data.Mail)
                {
                    NotifyChanging(argsMailChanging);
                    Data.Mail = value;
                    NotifyChangedAndDirty(argsMailChanged);
                }
            }
        }

        #endregion Mail

        #region Phone1

        private static PropertyChangedEventArgs argsPhone1Changed = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Phone1);

        private static PropertyChangingEventArgs argsPhone1Changing = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Phone1);

        public new string Phone1
        {
            get
            {
                return Data.Phone1;
            }

            set
            {
                if (value != Data.Phone1)
                {
                    NotifyChanging(argsPhone1Changing);
                    Data.Phone1 = value;
                    NotifyChangedAndDirty(argsPhone1Changed);
                }
            }
        }

        #endregion Phone1

        #region Phone2

        private static PropertyChangedEventArgs argsPhone2Changed = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.Phone2);

        private static PropertyChangingEventArgs argsPhone2Changing = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.Phone2);

        public new string Phone2
        {
            get
            {
                return Data.Phone2;
            }

            set
            {
                if (value != Data.Phone2)
                {
                    NotifyChanging(argsPhone2Changing);
                    Data.Phone2 = value;
                    NotifyChangedAndDirty(argsPhone2Changed);
                }
            }
        }

        #endregion Phone2

        #region UseAccountInfos

        private static PropertyChangedEventArgs argsUseAccountInfosChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.UseAccountInfos);

        private static PropertyChangingEventArgs argsUseAccountInfosChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.UseAccountInfos);

        public new bool UseAccountInfos
        {
            get
            {
                return Data.UseAccountInfos;
            }

            set
            {
                if (value != Data.UseAccountInfos)
                {
                    NotifyChanging(argsUseAccountInfosChanging);
                    Data.UseAccountInfos = value;
                    NotifyChangedAndDirty(argsUseAccountInfosChanged);
                }
            }
        }

        #endregion UseAccountInfos

        #region ZipCode

        private static PropertyChangedEventArgs argsZipCodeChanged = ObservableHelper.CreateChangedArgs<EditableContact>(x => x.ZipCode);

        private static PropertyChangingEventArgs argsZipCodeChanging = ObservableHelper.CreateChangingArgs<EditableContact>(x => x.ZipCode);

        public new string ZipCode
        {
            get
            {
                return Data.ZipCode;
            }

            set
            {
                if (value != Data.ZipCode)
                {
                    NotifyChanging(argsZipCodeChanging);
                    Data.ZipCode = value;
                    NotifyChangedAndDirty(argsZipCodeChanged);
                }
            }
        }

        #endregion ZipCode
    }
}